package cn.huanba.service;

import cn.huanba.dao.PictureDao;
import cn.huanba.entity.Picture;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Picture)表服务实现类
 *
 * @author makejava
 * @since 2021-01-07 17:23:29
 */
@RestController
@RequestMapping("picture")
public class PictureServiceImpl {
    @Resource
    private PictureDao pictureDao;

    /**
     * 通过ID查询单条数据
     *
     * @param picid 主键
     * @return 实例对象
     */
    @RequestMapping("queryById")
    public Picture queryById(@RequestParam("picid") Integer picid) {
        return this.pictureDao.queryById(picid);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @RequestMapping("queryAllByLimit")
    public List<Picture> queryAllByLimit(@RequestParam("offset") int offset,@RequestParam("limit") int limit) {
        return this.pictureDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param picture 实例对象
     * @return 实例对象
     */
    @RequestMapping("insert")
    public Picture insert(@RequestBody Picture picture) {
        this.pictureDao.insert(picture);
        return picture;
    }

    /**
     * 修改数据
     *
     * @param picture 实例对象
     * @return 实例对象
     */
    @RequestMapping("update")
    public Picture update(@RequestBody  Picture picture) {
        this.pictureDao.update(picture);
        return this.queryById(picture.getPicid());
    }

    /**
     * 通过主键删除数据
     *
     * @param picid 主键
     * @return 是否成功
     */
    @RequestMapping("deleteById")
    public boolean deleteById(@RequestParam("picid") Integer picid) {
        return this.pictureDao.deleteById(picid) > 0;
    }
}